package com.lkx.test;

import com.lkx.model.User;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName: RestfulController
 * Function:  RestfulController
 *
 * @Date: 2021年11月14日 15:02:29
 * @Author Kaixuan.Li01
 * version V1.0
 */
@RequestMapping("/restful/user")
@RestController
public class RestfulController {
    /**
     * 根据用户id查询用户数据
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    public ResponseEntity<User> queryUserById(@PathVariable("id") Long id) {
        User user = new User();
        user.setId(id);
        return ResponseEntity.ok(user);
    }

    /**
     * 新增用户
     *
     * @param user
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity saveUser(@RequestBody User user) {
        return ResponseEntity.ok(user);
    }

    @RequestMapping(method = RequestMethod.POST,value = "/save")
    public ResponseEntity save(@RequestBody Map<String,String> params) {
        return ResponseEntity.ok(new User());

    }

    /**
     * 更新用户资源
     *
     * @param user
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public ResponseEntity updateUser(@RequestBody User user) {
        return ResponseEntity.ok(user);
    }

    /**
     * 删除用户资源
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.DELETE)
    public ResponseEntity deleteUser(@RequestParam(value = "id", defaultValue = "0") Long id) {
        User user = new User();
        user.setId(id);
        return ResponseEntity.ok(user);
    }
}
